package com.kefu.chat.smart.condition;

import java.util.List;

import com.google.common.collect.Lists;
import com.kefu.chat.smart.ChatConnectCondition;
import com.kefu.chat.vo.ChatUserParam.UserConnectP;
import com.kefu.chat.vo.ChatUserParam.UserConnectR;
import com.kefu.common.trigger.Condition;
import com.kefu.common.trigger.Decision;
import com.kefu.common.trigger.TriggerWrapper;
import com.kefu.common.trigger.model.ConditionModel;
import com.kefu.common.trigger.model.DynamicModel.OptionType;

//@Component
public class ChatUserFormModeCondition implements ChatConnectCondition<Integer> {

	@Override
	public String getCode() {
		return "user_form_mode";
	}

	@Override
	public ConditionModel getConditionModel() {
		return ConditionModel.builder()
				.code(getCode())
				.name(getMessageName())
				.decisions(Lists.newArrayList(Decision.EQ))
				.optionType(OptionType.Simple)
				.children(conditionModelList(getMessageCodePrefix(),new String[][]{{"0","否"},{"1","是"}}))
				.build();
	}

	@Override
	public String getName() {
		return "是否提交过询前表单";
	}

	@Override
	public boolean match(TriggerWrapper<UserConnectP, UserConnectR> wrapper, Condition condition) {
		List<Integer> list=getOperatorList(condition,(c)->Integer.parseInt(c));
		return getChatUser(wrapper)!=null&&condition.getDecision().match(list, getChatUser(wrapper).getUserFormMode(),null);
	}

}
